<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>vue学习</title>
    <script src="./js/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <!-- 
        vue3自定义指令中才有的，叫变量
        bindings.arg
       -->
      <div v-title:h3.red="title"></div>
    </div>
    <script>
      const app = Vue.createApp({
        data() {
          return {
            title: '我是一个vue的自定义指令'
          }
        },
        directives: {
          title(el, bindings) {
            // 得到自定义指令中属性值
            const value = bindings.value
            const color = bindings.modifiers.red ? 'red' : 'black'
            // 得到自定义指令的变量名
            const tag = bindings.arg || 'div'
            el.innerHTML = `<${tag}>${value}</${tag}>`
            el.style.color = color
          }
        }
      })
      app.mount('#app')
    </script>
  </body>
</html>
